/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NewUserInputFrame.java
 *
 * Created on Jun 24, 2011, 9:25:44 AM
 */
package dynamicdiscountsystem;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

/**
 *
 * @author atilla1991
 */
public class NewUserInputFrame extends javax.swing.JInternalFrame {

    /** Creates new form NewUserInputFrame */
    public NewUserInputFrame() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jTextFieldUserName = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jPasswordField = new javax.swing.JPasswordField();
        jConfirmPasswordField = new javax.swing.JPasswordField();
        jLabel4 = new javax.swing.JLabel();
        jComboBoxUserType = new javax.swing.JComboBox();
        jPanel2 = new javax.swing.JPanel();
        jAddButton = new javax.swing.JButton();
        jUpdateButton = new javax.swing.JButton();
        jDeleteButton = new javax.swing.JButton();
        jShowButton = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        setAutoscrolls(true);
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
                formİnternalFrameActivated(evt);
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "İstifadəçi Məlumatları", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N

        jTextFieldUserName.setFont(new java.awt.Font("Tahoma", 0, 12));
        jTextFieldUserName.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jTextFieldUserNameFocusGained(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel1.setText("İstifadəçi Adı :");

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel2.setText("Şifrə :");

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel3.setText("Şifrənin Təkrarı :");

        jPasswordField.setFont(new java.awt.Font("Tahoma", 0, 12));
        jPasswordField.setText("jPasswordField1");
        jPasswordField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jPasswordFieldFocusGained(evt);
            }
        });

        jConfirmPasswordField.setFont(new java.awt.Font("Tahoma", 0, 12));
        jConfirmPasswordField.setText("jPasswordField1");
        jConfirmPasswordField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jConfirmPasswordFieldFocusGained(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel4.setText("Şifrənin Tipi :");

        jComboBoxUserType.setFont(new java.awt.Font("Tahoma", 0, 12));
        jComboBoxUserType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1. Administrator", "2. Standart" }));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextFieldUserName, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE)
                    .addComponent(jPasswordField, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE)
                    .addComponent(jComboBoxUserType, 0, 256, Short.MAX_VALUE)
                    .addComponent(jConfirmPasswordField, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldUserName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jConfirmPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jComboBoxUserType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(28, 28, 28))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Əməliyyatlar", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N

        jAddButton.setFont(new java.awt.Font("Tahoma", 0, 14));
        jAddButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/dynamicdiscountsystem/resources/ok.gif"))); // NOI18N
        jAddButton.setText("Əlavə Et");
        jAddButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jAddButtonActionPerformed(evt);
            }
        });

        jUpdateButton.setFont(new java.awt.Font("Tahoma", 0, 14));
        jUpdateButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/dynamicdiscountsystem/resources/update.png"))); // NOI18N
        jUpdateButton.setText("Dəyiş");
        jUpdateButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jUpdateButtonActionPerformed(evt);
            }
        });

        jDeleteButton.setFont(new java.awt.Font("Tahoma", 0, 14));
        jDeleteButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/dynamicdiscountsystem/resources/close.png"))); // NOI18N
        jDeleteButton.setText("Sil");
        jDeleteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jDeleteButtonActionPerformed(evt);
            }
        });

        jShowButton.setFont(new java.awt.Font("Tahoma", 0, 14));
        jShowButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/dynamicdiscountsystem/resources/download-database-icon.png"))); // NOI18N
        jShowButton.setText("Siyahını Yenilə");
        jShowButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jShowButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jUpdateButton, javax.swing.GroupLayout.DEFAULT_SIZE, 137, Short.MAX_VALUE)
                    .addComponent(jShowButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jDeleteButton, javax.swing.GroupLayout.DEFAULT_SIZE, 137, Short.MAX_VALUE)
                    .addComponent(jAddButton, javax.swing.GroupLayout.DEFAULT_SIZE, 137, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jShowButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jAddButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jUpdateButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jDeleteButton)
                .addGap(27, 27, 27))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "İstifadəçilərin Siyahısı", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "ID", "İstifadəçi Adı", "Şifrə", "İstifadəçi Tipi"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jTable1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTable1KeyReleased(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 641, Short.MAX_VALUE)
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 621, Short.MAX_VALUE)
                    .addContainerGap()))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 393, Short.MAX_VALUE)
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 371, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(59, 59, 59)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(100, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(23, 23, 23)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(72, 72, 72))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    int selectedItemId;

    public void updateFrame() {
        DatabaseConnection connect = new DatabaseConnection();
        DefaultTableModel model1 = (DefaultTableModel) jTable1.getModel();
        while (model1.getRowCount() > 0) {
            model1.removeRow(0);
        }
        String command = "SELECT * FROM USER_INFO ORDER BY USER_NAME ASC";
        try {
            ResultSet rs = connect.ExecuteQuery(command);
            while (rs.next()) {
                Integer idUserInfo = rs.getInt("idUSER_INFO");
                String userName = rs.getString("USER_NAME");
                String userPassword = rs.getString("USER_PASSWORD");
                String userType = rs.getString("USER_TYPE");

                Object[] newRow = new Object[]{idUserInfo, userName, userPassword, userType};
                model1.addRow(newRow);
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null,
                    "Xəta baş verdi! \nXəta mesajı = " + ex.getMessage(),
                    "XƏTA", JOptionPane.ERROR_MESSAGE);
        }


    }

    private void rowSelect(int selectedRow) {

        DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
        jTextFieldUserName.setText((String) model.getValueAt(selectedRow, 1));
        jPasswordField.setText((String) model.getValueAt(selectedRow, 2));
        jConfirmPasswordField.setText((String) model.getValueAt(selectedRow, 2));
        String useraType = (String) model.getValueAt(selectedRow, 3);
        if (useraType.compareTo("administrator") == 0) {
            jComboBoxUserType.setSelectedIndex(0);
        } else {
            jComboBoxUserType.setSelectedIndex(1);
        }

    }
    private void jShowButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jShowButtonActionPerformed

        updateFrame();

    }//GEN-LAST:event_jShowButtonActionPerformed

    private void jAddButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jAddButtonActionPerformed

        String userPassword = new String(jPasswordField.getPassword());
        String userConfirmPassword = new String(jConfirmPasswordField.getPassword());
        if (userPassword.compareTo(userConfirmPassword) == 0) {
            DatabaseConnection con = new DatabaseConnection();
            String userName = jTextFieldUserName.getText();
            String userType;
            if (jComboBoxUserType.getSelectedIndex() == 0) {
                userType = "administrator";
            } else {
                userType = "standard";
            }

            try {
                String message1 = "Məlumat əlavə olunsun?";
                int ret = JOptionPane.showConfirmDialog(this, message1, "Birini seçin", JOptionPane.YES_NO_OPTION);
                if (ret != 1) {
                    String command = "INSERT INTO USER_INFO (USER_NAME,USER_PASSWORD,USER_TYPE) "
                            + "VALUES('" + userName + "','" + userPassword + "','" + userType + "')";
                    con.Execute(command);
                    JOptionPane.showMessageDialog(this, "Məlumat əlavə olundu");
                    updateFrame();
                } else {
                    JOptionPane.showMessageDialog(this, "Məlumat əlavə olunmadı!");
                }
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(this, "Məlumat əlavə olunmadı!\n" + "Xəta mesajı = " + ex.getMessage());
            }
        } else {
            JOptionPane.showMessageDialog(this, "Şifrələr bir-birinə uyğun deyil!");
        }

    }//GEN-LAST:event_jAddButtonActionPerformed

    private void formİnternalFrameActivated(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formİnternalFrameActivated

        jTextFieldUserName.setText("İstifadəçi adı");
        this.setFocusable(true);
        updateFrame();
    }//GEN-LAST:event_formİnternalFrameActivated

    private void jTextFieldUserNameFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldUserNameFocusGained

        jTextFieldUserName.setText("");
    }//GEN-LAST:event_jTextFieldUserNameFocusGained

    private void jPasswordFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jPasswordFieldFocusGained
        jPasswordField.setText("");
    }//GEN-LAST:event_jPasswordFieldFocusGained

    private void jConfirmPasswordFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jConfirmPasswordFieldFocusGained

        jConfirmPasswordField.setText("");
    }//GEN-LAST:event_jConfirmPasswordFieldFocusGained

    private void jUpdateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jUpdateButtonActionPerformed

        String userPassword = new String(jPasswordField.getPassword());
        String userConfirmPassword = new String(jConfirmPasswordField.getPassword());
        if (userPassword.compareTo(userConfirmPassword) == 0) {
            String userName = jTextFieldUserName.getText();
            String userType;
            if (jComboBoxUserType.getSelectedIndex() == 0) {
                userType = "administrator";
            } else {
                userType = "standard";
            }

            int selectedIndex = jTable1.getSelectedRow();
            if (selectedIndex >= 0) {
                try {
                    String message1 = "Dəyişmək istədiyinizdən əminsinizmi?";
                    int ret = JOptionPane.showConfirmDialog(this, message1, "Birini seçin", JOptionPane.YES_NO_OPTION);
                    if (ret != 1) {
                        DatabaseConnection con = new DatabaseConnection();
                        String command = "UPDATE USER_INFO SET USER_NAME='" + userName
                                + "',USER_PASSWORD='" + userPassword + "'," + "USER_TYPE='" + userType + "'"
                                + "WHERE idUSER_INFO = '" + selectedItemId + "'";
                        con.Execute(command);
                        JOptionPane.showMessageDialog(this, "Məlumat dəyişildi!");
                        updateFrame();
                        con.ConnectionClose();
                    } else {
                        JOptionPane.showMessageDialog(this, "Məlumat dəyişilmədi!");
                    }
                } catch (Exception ex) {
                    JOptionPane.showMessageDialog(this, "Məlumat dəyişilmədi!" + "Xəta\n" + ex.getMessage());
                }
            } else {
                JOptionPane.showMessageDialog(this, "Dəyişiklik etmək istədiyiniz sətri seçin.");
            }
        } else {

            JOptionPane.showMessageDialog(this, "Şifrələr bir-birinə uyğun deyil!");
        }
    }//GEN-LAST:event_jUpdateButtonActionPerformed

    private void jTable1KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTable1KeyReleased

        int selectedRow = jTable1.getSelectedRow();
        selectedItemId = (Integer) jTable1.getValueAt(selectedRow, 0);
        rowSelect(selectedRow);
    }//GEN-LAST:event_jTable1KeyReleased

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
        int selectedRow = jTable1.getSelectedRow();
        selectedItemId = (Integer) jTable1.getValueAt(selectedRow, 0);
        rowSelect(selectedRow);
    }//GEN-LAST:event_jTable1MouseClicked

    private void jDeleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jDeleteButtonActionPerformed

        int selectedIndex = jTable1.getSelectedRow();
        if (selectedIndex >= 0) {
            DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
            try {
                String message1 = "Silmək istədiyinizdən əminsinizmi?";
                int ret = JOptionPane.showConfirmDialog(this, message1, "Birini seçin", JOptionPane.YES_NO_OPTION);
                if (ret != 1) {
                    DatabaseConnection con = new DatabaseConnection();
                    String command = "DELETE FROM USER_INFO WHERE idUSER_INFO = '" + selectedItemId + "'";
                    con.Execute(command);
                    JOptionPane.showMessageDialog(this, "Məlumat silindi");
                    updateFrame();
                } else {
                    JOptionPane.showMessageDialog(this, "Məlumat silinmədi");
                }
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(this, "Məlumat silinmədi" + "Xəta\n" + ex.getMessage());
            }
        } else {
            JOptionPane.showMessageDialog(this, "Silmək istədiyiniz sətri seçin");
        }
    }//GEN-LAST:event_jDeleteButtonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jAddButton;
    private javax.swing.JComboBox jComboBoxUserType;
    private javax.swing.JPasswordField jConfirmPasswordField;
    private javax.swing.JButton jDeleteButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPasswordField jPasswordField;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jShowButton;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextFieldUserName;
    private javax.swing.JButton jUpdateButton;
    // End of variables declaration//GEN-END:variables
}
